# -*- coding: utf-8 -*-
# @Time : 2019/1/11 11:21
# @Author : Administrator
# @File : read_excel.py
# @Project : untitled
# @title :表格数据读取
import xlrd
class ReadExcel():
    def read_data(self,excelpath,sheetname):
        data = xlrd.open_workbook(excelpath)
        table = data.sheet_by_name(sheetname)
        rows = table.nrows  #获取表格总行数
        tel_key = table.row_values(0)[0]
        name_key = table.row_values(0)[1]
        QQ_key = table.row_values(0)[2]
        school_key = table.row_values(0)[3]
        major_key = table.row_values(0)[4]
        job_key = table.row_values(0)[5]
        age_key = table.row_values(0)[6]
        exp_key = table.row_values(0)[7]
        fav_key = table.row_values(0)[8]
        expect_key = table.row_values(0)[9]
        list = []  #定义一个列表，用来存放字典
        for i in range(1,rows):
            dict = {}  #定义字典
            dict[tel_key] = table.row_values(i)[0] #关联键和值
            dict[name_key] = table.row_values(i)[1]
            dict[QQ_key] = table.row_values(i)[2]
            dict[school_key] = table.row_values(i)[3]
            dict[major_key] = table.row_values(i)[4]
            dict[job_key] = table.row_values(i)[5]
            dict[age_key] = table.row_values(i)[6]
            dict[exp_key] = table.row_values(i)[7]
            dict[fav_key] = table.row_values(i)[8]
            dict[expect_key] = table.row_values(i)[9]
            list.append(dict)  #将字典传入列表中
        return list

if __name__ == '__main__':
    uesrinfo = ReadExcel()
    data=uesrinfo.read_data(r"C:\Users\Administrator\PycharmProjects\untitled\WoniuBoss2\interface\data\resourse.xls","王者荣耀")
    print(data)

